package cn.wolfcode.service.impl;

import cn.wolfcode.domain.MenuCatalogue;
import cn.wolfcode.mapper.MenuCatalogueMapper;
import cn.wolfcode.qo.MenuCatalogueObject;
import cn.wolfcode.service.IMenuCatalogueService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
public class MenuCatalogueServiceImpl implements IMenuCatalogueService {

    @Autowired
    private MenuCatalogueMapper menuCatalogueMapper;

    @Override
    @Transactional
    public void save(MenuCatalogue menuCatalogue) {
        menuCatalogueMapper.insert(menuCatalogue);
    }

    @Override
    @Transactional
    public void delete(Long id) {
        menuCatalogueMapper.deleteByPrimaryKey(id);
    }

    @Override
    @Transactional
    public void update(MenuCatalogue menuCatalogue) {
        menuCatalogueMapper.updateByPrimaryKey(menuCatalogue);
    }

    @Override
    public MenuCatalogue get(Long id) {
        return menuCatalogueMapper.selectByPrimaryKey(id);
    }

    @Override
    public List<MenuCatalogue> listAll() {
        return menuCatalogueMapper.selectAll();
    }

    @Override
    public PageInfo<MenuCatalogue> query(MenuCatalogueObject qo) {
        // 告诉插件我们查询的是第几页，每页多少条
        PageHelper.startPage(qo.getCurrentPage(), qo.getPageSize());
        // 查询当前页的数据
        List<MenuCatalogue> menuCatalogues = menuCatalogueMapper.selectForList(qo);
        return new PageInfo<>(menuCatalogues);
    }

    @Override
    public void updateStatus(Long id, int status) {
        menuCatalogueMapper.updateStatus(id,status);
    }
}
